package lvbu.wang.lvbuoperator.utils;

import android.support.annotation.NonNull;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by DaiQing.Zha on 2016/6/14 0014.
 * Email:1642674371@qq.com
 * Description:
 */
public class StringHelper {
    /**
     * 判断蓝牙地址是否正确
     *
     * @param bluetoothAddress
     * @return
     */
    public static Boolean checkBluetoothAddress(String bluetoothAddress) {
        if (bluetoothAddress != null && bluetoothAddress.length() != 17) {
            return false;
        }
        return true;
    }
    /**
     * 判断手机号码是否正确
     * @param phone
     * @return
     */
    public static Boolean checkPhone(String phone) {
        String regExp = "^[1][345678][0-9]{9}$";
        Pattern p = Pattern.compile(regExp);
        Matcher m = p.matcher(phone);
        return m.matches();
    }
    /**
     * 判断密码输入格式是否正确
     *
     * @param password
     * @return
     */
    public static Boolean checkPasswordInput(String password) {
        password = password.trim();
        if (password.length() < 6) {
            return false;
        }
        return true;
    }

    @NonNull
    public static String subString(@NonNull String str, int start,int end){
        try{
            str = str.substring(start,end);
        }catch (Exception e){
            str = "";
        }
        return str;
    }
    @NonNull
    public static String subString(@NonNull String str, int start){
        try{
            str = str.substring(start);
        }catch (Exception e){
            str = "";
        }
        return str;
    }
}
